{% extends 'base.html' %}
{% load form_helpers %}

{% block title %}Add {{ model_name|title }}{% endblock %}

{% block content %}
    <form action="." method="post" class="h-100 vstack">
        {% csrf_token %}
        {% if request.POST.return_url %}
            <input type="hidden" name="return_url" value="{{ request.POST.return_url }}" />
        {% endif %}
        {% for field in form.hidden_fields %}
            {{ field }}
        {% endfor %}
        <div class="row align-content-start flex-fill">
            <p class="mb-16">{{ table.rows|length }} {{ parent_model_name }} selected</p>
            <div class="col-lg-7">
                <div class="card">
                    <div class="table-responsive">
                        {% include 'inc/table.html' %}
                    </div>
                </div>
            </div>
            <div class="col-lg-5">
                {% if form.non_field_errors %}
                    <div class="card border-danger">
                        <div class="card-header bg-danger-subtle border-danger text-body">
                            <strong>Errors</strong>
                        </div>
                        <div class="card-body">
                            {{ form.non_field_errors }}
                        </div>
                    </div>
                {% endif %}
                <div class="card">
                    <div class="card-header"><strong>{{ model_name|title }} to Add</strong></div>
                    <div class="card-body">
                        {% for field in form.visible_fields %}
                            {% if not form.custom_fields or field.name not in form.custom_fields %}
                                {% render_field field %}
                            {% endif %}
                        {% endfor %}
                        {% if form.custom_fields %}
                            {% render_custom_fields form %}
                        {% endif %}
                    </div>
                </div>
            </div>
        </div>
        <div class="nb-form-sticky-footer">
            <button type="submit" name="_create" class="btn btn-primary">
                <span aria-hidden="true" class="mdi mdi-check me-4"></span><!--
                -->Create
            </button>
            <a href="{{ return_url }}" class="btn btn-secondary">
                <span aria-hidden="true" class="mdi mdi-close me-4"></span><!--
                -->Cancel
            </a>
        </div>
    </form>
{% endblock %}
